package com.waiting.hessian.demo;

import com.caucho.hessian.io.HessianInput;
import com.caucho.hessian.io.HessianOutput;
import com.netease.rmi.server.User;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @author bjweitingting
 * @description
 * @date 2018/8/31
 **/
public class HessianDemo {
    private static String constant1 = "waiting";

    public static void main(String[] args) throws IOException {

        User zhansan = new User();
        zhansan.setName("张三");
        zhansan.setAge(22);

        ByteArrayOutputStream os = new ByteArrayOutputStream();

        //Hessian的序列化输出
        HessianOutput ho = new HessianOutput(os);

        ho.writeObject(zhansan);

        byte[] zhansanByte = os.toByteArray();

        ByteArrayInputStream is = new ByteArrayInputStream(zhansanByte);
        //Hessian的反序列化读取对象
        HessianInput hi = new HessianInput(is);
        User person = (User) hi.readObject();
        System.out.println("姓名：" + person.getName());
        System.out.println("年龄：" + person.getAge());
    }
}
